<?php include template('header','common');?>
<link rel="stylesheet" type="text/css" href="{__ROOT__}template/default/statics/css/bianji.css?v={HD_VERSION}">
<script type="text/javascript" src="{__ROOT__}statics/js/haidao.validate.js?v={HD_VERSION}"></script>
<style>
.upload-img-li font{width: 23%;
    height: 80px;
    margin-bottom: 18px;
    margin-right: 6px;
}
.upload-img-li font img{width: 100%;
    height: 100%; margin:0;
}
</style>
<form class="padding-small" method="post" action='{url("add",array("formhash"=>FORMHASH))}' name="checkmobile">
<div class="container">
	<div class="content">
		<textarea class="add-content" name="title" id="" cols="30" rows="10" placeholder="这一刻的想法"></textarea>
		<div class="upload-img-li">
			{if $img}
			<font><img src="{$img}" alt=""><input type="hidden" name="material[]" value="{$img}"></font>
			{/if}
			<font id="img-box" style="position:relative;">	
			<span id="file-avatar" style=" position:absolute;"><img src="{__ROOT__}template/default/statics/img/tianjia.png" alt=""></span>
			</font>
		</div>
	</div>
	<div class="btn-view">
		<button class="btn2" type="button">取消</button>
		<button class="btn1">发送</button>
	</div>
</div>
</form>
<link type="text/css" rel="stylesheet" href="{__ROOT__}statics/js/upload/uploader.css?v={HD_VERSION}" />
<script type="text/javascript" src="{__ROOT__}statics/js/upload/uploader.js?v={HD_VERSION}"></script>
<script>
	$(".btn2").click(function(){
		window.location.href="<?php echo url('school/ring/index')?>";
	});
	
	var resetmobile = $("form[name=checkmobile]").Validform({
		ajaxPost:true,
		beforeCheck:function(){
			if($("textarea[name=title]").val() == ''){
				alerts('请填写内容');
				$("textarea[name=title]").focus();
				return false;
			}
		},
		callback:function(ret){
			if(ret.status == 1){
				//alerts(ret.message,1,ret.referer);
				window.location.href=ret.referer;
			}else{
				alerts(ret.message);
			}
		}		
	});
	
	var uploader = WebUploader.create({
		auto:true,
		chunked: false,
		fileVal:'upfile',
		// swf文件路径
		swf: '{__ROOT__}statics/js/upload/uploader.swf',
		// 文件接收服务端。
		server: "<?php echo url('attachment/index/upload')?>",
		// 选择文件的按钮。可选
		formData:{
			file : 'upfile',
			upload_init : '<?php echo $attachment_init ?>'
		},
		// 压缩图片大小
		/*compress:{
			width: 408,
			height: 408,
			quality: 80,
			allowMagnify: false
		},*/
		// 内部根据当前运行是创建，可能是input元素，也可能是flash.
		pick: {
			id: '#file-avatar',
			multiple:false
		},
		accept:{
			title: '图片文件',
			//extensions: 'gif,jpg,jpeg,bmp,png',
			mimeType: 'image/*'
		},
		chunked: false,
		chunkSize:1000000,
		resize: false
	});
	uploader.onFileQueued = function(file){
		alerts("图片上传中...", 3);
	}
	uploader.onUploadError = function(file,reason){
		alerts("图片上传失败");
	}
	uploader.onUploadSuccess = function(file, response) {
		if(response.status == 1) {
			layer.closeAll();
			$("#img-box").before('<font><img src="'+response.result.url+'" alt=""><input type="hidden" name="material[]" value="'+response.result.url+'"></font>');
		} else {
			alerts(response.message);
		}
	}
</script>
<?php include template('footer','common');?>